package com.blindBox.front.handler.tokenHandler;

import com.blindBox.front.dao_pojo.User;
import com.blindBox.front.token.TokenTool;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

//处理token
@Component
public class TokenHandler
{
    @Autowired
    private TokenTool tokenTool;
    private ObjectMapper objectMapper=new ObjectMapper();
    //获取过期时间
    @Value("${token.expire-time}")
    private Integer expireTime;
    //对用户名和密码进行加密后返回，并设置过期时间
    public  String encryptionUnameAndUpwd(User user) throws JsonProcessingException
    {
        System.out.println(objectMapper.writeValueAsString(user));
        return tokenTool.encipher(objectMapper.writeValueAsString(user),expireTime);
    }
}
